#include <iostream>
#include <algorithm>
using namespace std;

typedef struct SECTION
{
    int l;
    int r;
    //左端点和右端点
    bool operator<(struct SECTION other)
    {
        return r < other.r;
    }

    bool operator>(struct SECTION other)
    {
        return r > other.r;
    }
    //重载大于小于号，方便排序
} section;

const int N = 100010;
const int INF = 0x3f3f3f3f;

int n;
section sec[N];
int res = 0;
int ed = -INF; //先初始化为极小值

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> sec[i].l >> sec[i].r;
    sort(sec, sec + n);
    for (int i = 0; i < n; ++i)
        if (sec[i].l > ed) //新的区间不包括在旧区间中
        {
            ed = sec[i].r;
            res++;
        }
    cout << res;
}